package com.uzai.console.web.wechatwork;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.DeviceTypeGroupEnum;
import com.uzai.common.exception.BusinessException;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.config.UzaiConsoleSysConfig;
import com.uzai.console.dto.wechatprivate.configplan.*;
import com.uzai.console.dto.wechatwork.wxq.manageplan.WxqWorkManagePlanIdDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.SysConfigMapper;
import com.uzai.console.mapper.SysDomainMapper;
import com.uzai.console.mapper.UserTypeGroupMapper;
import com.uzai.console.service.configplan.ConfigPlanService;
import com.uzai.console.service.wechatwork.WxqWorkManagePlanService;
import com.uzai.console.vo.sysplugin.SysPluginVo;
import com.uzai.console.vo.wechatprivate.configplan.ConfigPlanSelectListVo;
import com.uzai.console.vo.wechatprivate.configplan.ConfigPlanVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 企业微信微信群管理方案
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "企业微信微信群管理方案", tags = "企业微信|微信群|管理方案")
@ApiSort(6)
@RestController
public class WxqWorkManagePlanController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(WxqWorkManagePlanController.class);

    @Autowired
    private WxqWorkManagePlanService wxqWorkManagePlanService;
    @Autowired
    private UserTypeGroupMapper userTypeGroupMapper;
    @Autowired
    private SysConfigMapper sysConfigMapper;
    @Autowired
    private SysDomainMapper sysDomainMapper;
    @Autowired
    private UzaiConsoleSysConfig uzaiConsoleSysConfig;
    @Autowired
    private ConfigPlanService configPlanService;

    @ApiOperation(value = "查询企业微信群配置列表", response = ConfigPlanSelectListVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/wxqWorkManagePlan/findWxqWorkManagePlanList")
    public Object findWxqWorkManagePlanList(@RequestBody ConfigPlanQuery param) {
        param.setDeviceType(DeviceTypeGroupEnum.WORK_WECHAT_GROUP.getKey());
        return configPlanService.findConfigPlanSelectList(param);
    }

    @ApiOperation(value = "查询企业微信群配置详情", response = ConfigPlanVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxqWorkManagePlan/findWxqWorkManagePlanInfo")
    public Object findWxqWorkManagePlanInfo(@RequestBody ConfigPlanIdDto param) {
        return configPlanService.findConfigPlanInfo(param);
    }

    @ApiOperation(value = "修改企业微信群配置")
    @ApiOperationSupport(order = 3)
    @PostMapping("/wxqWorkManagePlan/updateWxqWorkManagePlan")
    public Object updateWxqWorkManagePlan(@RequestBody ConfigPlanUpdateDto param) {
        configPlanService.updateConfigPlan(param);
        return true;
    }

    @ApiOperation(value = "删除企业微信群配置")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wxqWorkManagePlan/deleteWxqWorkManagePlan")
    public Object deleteWxqWorkManagePlan(@RequestBody ConfigPlanIdDto param) {
        configPlanService.deleteConfigPlan(param);
        return true;
    }

    @ApiOperation(value = "添加企业微信群配置", response = ConfigPlanIdDto.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/wxqWorkManagePlan/addWxqWorkManagePlan")
    public Object addWxqWorkManagePlan(@RequestBody ConfigPlanAddDto param) {
        param.setDeviceType(DeviceTypeGroupEnum.WORK_WECHAT_GROUP.getKey());
        Long id = configPlanService.addConfigPlan(param);
        ConfigPlanIdDto newConfigPlanIdDto = new ConfigPlanIdDto();
        newConfigPlanIdDto.setId(id);
        return newConfigPlanIdDto;
    }


    @ApiOperation(value = "查询企业微信群插件详情", response = SysPluginVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/wxqWorkManagePlan/findSysPluginInfo")
    public Object findSysPluginInfo(@RequestBody ConfigPlanPluginIdDto param) {
        if (Objects.isNull(param) || Objects.isNull(param.getId())) {
            throw new BusinessException("企业微信群配置详情参数错误");
        }
        //return wxqWorkManagePlanService.findSysPluginInfo(param);
        return configPlanService.findSysPluginInfo(param);
    }

//    @ApiOperation(value = "修改企业微信群插件信息", response = ConfigPlanPluginIdDto.class)
//    @ApiOperationSupport(order = 8)
//    @PostMapping("/wxqWorkManagePlan/updateSysPlugin")
//    public Object updateSysPlugin(@RequestBody ConfigPlanPluginUpdateDto param) {
//        if (Objects.isNull(param) || StringUtils.isAnyBlank(param.getData(), param.getPlugName())
//                || Objects.isNull(param.getConfigPlanID())) {
//            throw new BusinessException("企业微信群配置修改参数错误");
//        }
//        Long id = wxqWorkManagePlanService.updateSysPlugin(param);
//        ConfigPlanPluginIdDto configPlanPluginIdDto = new ConfigPlanPluginIdDto();
//        configPlanPluginIdDto.setId(id);
//        return configPlanPluginIdDto;
//    }

}
